# coding: utf-8
from . import db, BaseModel

from .sso_user import SsoUser




class UserToken(db.Model):
    __tablename__ = 'user_token'

    autoID = db.Column(db.BigInteger, primary_key=True, info='自增主键')
    userID = db.Column(db.ForeignKey('sso_user.userID', ondelete='CASCADE', onupdate='CASCADE'), nullable=False, index=True, info='用户id')
    userType = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue(), info='用户类型 0-普通用户； 1-管理员；2-超级管理员')
    token = db.Column(db.String(255, 'utf8mb4_0900_ai_ci'), nullable=False, server_default=db.FetchedValue(), info='token值')
    expireTime = db.Column(db.DateTime, nullable=False, info='超时时间')
    isValid = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue(), info='token是否可用 1-可用 0-不可用')
    isDelete = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue(), info='逻辑删除')
    createTime = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue(), info='创建时间')
    updateTime = db.Column(db.DateTime, nullable=False, server_default=db.FetchedValue(), info='更新时间')

    sso_user = db.relationship('SsoUser', primaryjoin='UserToken.userID == SsoUser.userID', backref='user_tokens')
